import { service } from '@/utils/axios'

const BASE_URL = '/v1/users'
// 新增
export function addUser(data: any): Promise<any> {
  return service({
    url: BASE_URL,
    method: 'post',
    data
  })
}

// 更新
export function updateUser(userCode: any, data: any): Promise<any> {
  return service({
    url: `${BASE_URL}/${userCode}`,
    method: 'put',
    data
  })
}

export function deleteUser(userCodes: any): Promise<any> {
  return service({
    url: `${BASE_URL}/${userCodes}`,
    method: 'delete'
  })
}

export function getUserPageList(data: any) {
  return service({
    url: `${BASE_URL}/page`,
    method: 'get',
    params: data
  })
}

export function getUserForm(userCode: any): Promise<any> {
  return service({
    url: `${BASE_URL}/${userCode}/form`,
    method: 'get'
  })
}

export function updateUserStatus(id: any, status: any): Promise<any> {
  return service({
    url: `${BASE_URL}/${id}/status`,
    method: 'put',
    params: {
      status: status
    }
  })
}

export function getUserPassword(userCode: any): Promise<any> {
  return service({
    url: `${BASE_URL}/${userCode}/password`,
    method: 'get'
  })
}

export function getUserInfo(): Promise<any> {
  return service({
    url: `${BASE_URL}/me`,
    method: 'get'
  })
}

export function updateUserPassword(userCode: any, password: any): Promise<any> {
  return service({
    url: `${BASE_URL}/${userCode}/password/reset`,
    method: 'put',
    params: {
      password: password
    }
  })
}

export function importUser(file: any): Promise<any> {
  return service({
    url: `${BASE_URL}/import`,
    method: 'post',
    data: file,
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    timeout: 60 * 1000
  })
}

export function importTemplate(): Promise<any> {
  return service({
    url: `${BASE_URL}/template`,
    method: 'get',
    responseType: 'blob',
    timeout: 60 * 1000
  })
}

export function exportUser(data: any): Promise<any> {
  return service({
    url: `${BASE_URL}/export`,
    method: 'get',
    params: data,
    responseType: 'blob',
    timeout: 60 * 1000
  })
}

export function optionsUser(data: any): Promise<any> {
  return service({
    url: `${BASE_URL}/options`,
    method: 'get',
    params: data
  })
}
